<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <title>Document</title>
</head>
<body>
    <input type="button" value="get请求" class="get"/>
    <input type="button" value="post请求" class="post"/>
    <ul class="jokeList">
    </ul>
    <div id="app4">
        <input type="button" @click="getJoke" value="获取笑话"/>
        <p>{{joke}}</p>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        //随机笑话
        document.querySelector(".get").onclick = function(){
            axios.get("https://autumnfish.cn/api/joke/list?num=3").then(
                function(response){
                    console.log(response);
                    console.log(response.data.jokes.length);
                    for(var i=0;i<response.data.jokes.length;i++)
                    {
                        document.querySelector(".jokeList").innerHTML +=`<li>${response.data.jokes[i]}</li>`
                        // console.log(response.data.jokes[i])
                    }      
                },function(err){
                    console.log(err)
                }
            )
        }

        //用户注册
        document.querySelector(".post").onclick = function(){
            axios.post("https://autumnfish.cn/api/user/reg",{username:"cqgm"}).then(function(response){
                console.log(response);
            },function(err){
                console.log(err)
            })
        }
    </script>
    <script>
        var app = new Vue({
            el:"#app4",
            data:{
                joke:"很好笑的笑话"
            },
            methods:{
                getJoke:function(){
                    axios.get("https://autumnfish.cn/api/joke").then(function(response){
                        console.log(response.data)
                    },function(err){

                    })
                }
            }
        })
    </script>
</body>
</html>